﻿var EMAIL_REGULAR_EXPRESSION="(\\w|[-.])+@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
var PASSWORD_REGULAR_EXPRESSION="^\\w{6,12}$";
var NICKNAME_REGULAR_EXPRESSION="^[a-z0-9\\u4e00-\\u9fa5]{2,20}$";
var VERIFY_CODE_EXPRESSION="^\\d{4}$";
var NUMBER_IS_EXPRESSION="^[0-9]*$";

var MSG_NICKNAME_USED="该昵称已被注册";
var MSG_EMAIL_USED="该E-mail已被注册";
var MSG_VERIFYCODE_ERROR = "验证码不正确";
var MSG_COOKIE_DISABLED = "登录之前请您先打开浏览器的Cookie功能。";
var MSG_EMAIL_FORMAT_ERROR = "Email格式不正确";
var MSG_NICKNAME_FORMAT_ERROR = "昵称格式不正确";
var MSG_PASSWORD_FORMAT_ERROR = "密码不符合规则";
var MSG_PASSWORD_NOT_IDENTICAL ="密码不一致";
var MSG_VERIFY_CODE_FORMAT_ERROR = "四位数字";
var MSG_NUMBER_IS_FORMAT_ERROR = "请填写数字";
var MSG_PROVINCE_FORMAT_ERROR = "请选择省";
var MSG_CITY_FORMAT_ERROR = "请选择城市";

String.prototype.trim=function() 
{ 
	return this.replace(/(\s*$)|(^\s*)/g, ''); 
} 

function requireFieldValid(controlToValidID,msgSpanID,errorMessage)
{
    var objControlToValid=document.getElementById(controlToValidID);
    var objMsgSpan=document.getElementById(msgSpanID);
    var isValid=objControlToValid.value.trim()!='';
    objMsgSpan.style.color = "red";
    objMsgSpan.innerHTML=isValid?'':errorMessage;
    return isValid;
}

function compareFieldValid(controlToValidID,compareToValidID,msgSpanID,errorMessage)
{
	var objControlToValid=document.getElementById(controlToValidID);
	var objCompareToValid=document.getElementById(compareToValidID);
	var objMsgSpan=document.getElementById(msgSpanID);
	var isValid=objControlToValid.value.trim()==objCompareToValid.value.trim();
	objMsgSpan.style.color = "red";
    objMsgSpan.innerHTML=isValid? '' : errorMessage;
    return isValid;
}

function regularExpressionValid(controlToValidID,validationExpression,msgSpanID,errorMessage)
{
    var objRegExp = new RegExp(validationExpression,"g");
    var objControlToValid=document.getElementById(controlToValidID);
    var objMsgSpan=document.getElementById(msgSpanID);
    var isValid=objRegExp.test(objControlToValid.value);
    objMsgSpan.style.color = "red";
    objMsgSpan.innerHTML=isValid? '' : errorMessage;
    return isValid;
}


function requireRadFieldValid(RadOne,RadTwo,msgSpanID,errorMessage)
{
    var isValid;
    var objRadOne=document.getElementById(RadOne);
    var objRadTwo=document.getElementById(RadTwo);
    var objMsgSpan=document.getElementById(msgSpanID);
    isValid=objRadOne.checked!=''||objRadTwo.checked!='';   
    objMsgSpan.style.color = "red"; 
    objMsgSpan.innerHTML=isValid?'':errorMessage;
    return isValid;
}

//判断省和城市
function requireSelectValid(controlToValidID,msgSpanID,errorMessage)
{
    var objControlToValid=document.getElementById(controlToValidID);
    var objMsgSpan=document.getElementById(msgSpanID);
    var isValid=objControlToValid.value>0;
    objMsgSpan.style.color = "red";
    objMsgSpan.innerHTML=isValid?'':errorMessage;
    return isValid;
}

//验证是否为数字
function isNumber(oNum)
{
    if(!oNum) return false;
    var strP=/^\d+(\.\d+)?$/;
    if(!strP.test(oNum)) return false;
    try{
    if(parseFloat(oNum)!=oNum) return false;
}
catch(ex)
{
    return false;
}
    return true;
}